/*
 * $Id: TaskListTag.java,v 1.8 2009/07/21 19:42:46 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.onwatch.xml.tag;

import java.util.ArrayList;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.annotations.XStreamOmitField;

@XStreamAlias("taskList")
public class TaskListTag {
	@XStreamAsAttribute
	private String id = null;
	@XStreamAsAttribute
	private String systemId = null;
	@XStreamAsAttribute
	private String modelType = null;
	@XStreamAsAttribute
	private String iipVersion = null;
	private String taskListStatus = null;
	@XStreamOmitField
	private boolean failed = false;
	@XStreamImplicit
	private ArrayList<TaskTag> tasks = new ArrayList<TaskTag>();
	@XStreamImplicit
	private ArrayList<TaskRequestTag> taskRequests = new ArrayList<TaskRequestTag>();
	@XStreamOmitField
	private TaskResultTag taskResult = null;
	
	
	public TaskListTag() {}
	
	public TaskListTag(String systemId, String iipVersion) {
		this.systemId = systemId;
		this.iipVersion = iipVersion;
	}
	
	public TaskListTag(Long id,
						String systemId,
						String iipVersion) {
		this.id = id.toString();
		this.systemId = systemId;
		this.iipVersion = iipVersion;
	}
	
	public void addTask(TaskTag task) {
		tasks.add(task);
	}
	
	public ArrayList<TaskTag> getTasks() {
		return tasks;
	}
	
	public void addTaskRequest(TaskRequestTag taskRequest) {
		taskRequests.add(taskRequest);
	}

	public ArrayList<TaskRequestTag> getTaskRequests() {
		return taskRequests;
	}
	
	public void setTaskResult(TaskResultTag taskResult) {
		this.taskResult = taskResult;
	}
	
	public TaskResultTag getTaskResult() {
		return taskResult;
	}
	
	public void setSystemId(String systemId) {
		this.systemId = systemId;
	}
	
	public String getSystemId() {
		return systemId;
	}
	
	public String getModelType() {
		return modelType;
	}

	public void setModelType(String modelType) {
		this.modelType = modelType;
	}
	
	public String getIipVersion() {
		return iipVersion;
	}

	public void setIipVersion(String iipVersion) {
		this.iipVersion = iipVersion;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTaskListStatus() {
		return taskListStatus;
	}

	public void setTaskListStatus(String taskListStatus) {
		this.taskListStatus = taskListStatus;
	}
	
	public void markAsFailure() {
		failed = true;
	}
	
	public boolean isFailed() {
		return failed;
	}
	
	public String toString() {
		StringBuffer msg = new StringBuffer();
		msg.append(TaskListTag.class.getName()).append(":\n");
		msg.append("{Id: ").append(getId()).append("},");
		msg.append("{systemId: ").append(getSystemId()).append("},");
		msg.append("{modelType: ").append(getModelType()).append("},");
		msg.append("{iipVersion: ").append(getIipVersion()).append("},");
		msg.append("{taskListStatus: ").append(getTaskListStatus()).append("},");
		if(isFailed()) {
			msg.append("{failed: true}");
		} else {
			msg.append("{failed: false}");
		}
		msg.append("\n");
		if(taskResult != null) {
			msg.append(taskResult);
		}
		for(TaskTag taskTag: tasks) {
			msg.append(taskTag);
		}
		for(TaskRequestTag taskRequestTag: taskRequests) {
			msg.append(taskRequestTag);
		}
		msg.append("\n");
		return msg.toString();
	}
}
